package com.shanghaiyimu.yimiyangche.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

import com.shanghaiyimu.yimiyangche.R;
import com.shanghaiyimu.yimiyangche.bean.BaoYnagSelectShopBean;

import java.util.List;

/**
 * Author:ShangHaiYiMu
 * Time:2017/7/20   10:12
 * Description:BaoyangShopselectAListViewdapter
 */

public class BaoyangShopselectAListViewdapter extends BaseAdapter {
    private Context context;
    private List<BaoYnagSelectShopBean> datas;

    public BaoyangShopselectAListViewdapter(Context context, List<BaoYnagSelectShopBean> datas) {
        this.context = context;
        this.datas = datas;
    }

    @Override
    public int getCount() {
        return datas!=null?datas.size():0;
    }

    @Override
    public Object getItem(int position) {
        return datas.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder = null;
        if (convertView == null) {
            convertView = LayoutInflater.from(context).inflate(R.layout.baoyangselect_shop_item,parent,false);
            holder = new ViewHolder(convertView);
            convertView.setTag(holder);
        }else {
            holder = (ViewHolder) convertView.getTag();
        }
        final BaoYnagSelectShopBean baoYnagSelectShopBean = datas.get(position);
        holder.name.setText(baoYnagSelectShopBean.getName());
        holder.address.setText(baoYnagSelectShopBean.getAddress());
        holder.assess.setText("评价："+baoYnagSelectShopBean.getAssess());
        holder.distance.setText("距离:"+baoYnagSelectShopBean.getDistance());
        holder.call.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Toast.makeText(context,"给"+baoYnagSelectShopBean.getName()+"打电话",Toast.LENGTH_SHORT).show();
            }
        });
        return convertView;
    }
    static class ViewHolder{

        private TextView name;
        private TextView address;
        private TextView assess;
        private TextView distance;
        private ImageView call;

        public ViewHolder(View view) {
            name = (TextView) view.findViewById(R.id.name_shop_select_baoyang);
            address = (TextView) view.findViewById(R.id.address_baoyang_select_shop_item);
            assess = (TextView) view.findViewById(R.id.pingjia_select_shop_baoyang_item);
            distance = (TextView) view.findViewById(R.id.distance_select_shop_baoyang_item);
            call = (ImageView) view.findViewById(R.id.call_shop_baoyang);
        }
    }
}
